package stringMatching;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Solution {
    public List<String> stringMatching(String[] words) {
        Set<String> set = new HashSet<>();
        for (int i = 0; i < words.length; i++) {
            for (int j = i+1; j < words.length; j++) {
                    if(check(words[i],words[j])){
                        set.add(words[j].length()>words[i].length()?words[i]:words[j]);
                }
            }
        }
        return set.stream().toList();
    }
    private boolean check(String s1,String s2){
        return s1.contains(s2)||s2.contains(s1);
    }
}
